set more off

use dataset, clear

keep if year <= 2012

*** trim outliers ***

su dtaxbill , det
replace dtaxbill = . if dtaxbill < `r(p1)' | dtaxbill > `r(p99)'

*** covariates ***

local controls dfederalaidpcp dstateaidpcp lpopulation pct_white pct_senior pct_renter lmedianincome 
local economy davgannualwage demployment dunemployment propvaluechange

*** make interactions ***

label variable overridep "Tax increase"
label variable davg "Average wages"
label variable propvalue "Property values"
label variable dunemployment "Unemployment"
label variable demployment "Employment"
label variable dstateaidpcp "State aid"
label variable dfederal "Federal grants"

*** do the regressions ***

tabulate year, gen(year_)

foreach x in `controls' `economy' {
	su `x'
	replace `x' = (`x' - `r(min)') / (`r(max)' - `r(min)')
}
eststo clear

eststo: xi: reg dtaxbill ltaxbill overridep year_* , cl(town)

eststo: xi: reg dtaxbill ltaxbill overridep `economy' `controls' year_*, cl(town) 

eststo: xi: reg dtaxbill ltaxbill overridep year_* if !mi(demvoteshare), cl(town)

eststo: xi: reg dtaxbill ltaxbill overridep `economy' `controls' year_* if !mi(demvoteshare), cl(town) 

#delimit;

esttab
	using "table A2.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		order(overridepassed davgannualwage demployment dunemployment propvaluechange dfederalaidpcp dstateaidpcp)
		drop(*year*)
		gap
		indicate(
			"Lagged tax bill = ltaxbill"
			"Year fixed effects = year_1"			
		)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		stats(
			N
			N_clust
			,
				label(
					"Observations"
					"Towns"
						
				)
				fmt(%20.0fc)
		)
		;
	
#delimit cr
 
